<?php
 include "counter.php";
 requirelogin();
 $u = User::create(); // object for currently logged-in user
 pagestart();
?>
<HTML>
<?php pagehead("Home page for #" . $u->userid . " ".  $u->pfields[name]) ?>
<BODY>
<?php pagetop() ?>
<h1><img src="/gifs/Logo-small.png" alt="Linux Counter Logo">
<?php echo("Home page for #" . $u->userid . " ".  $u->pfields[name]) ?>
</h1>
<h2>My registration information</h2>
<table class="info">
<tr><td class="info">Registration created</td>
<td class="info"><?php echo $u->ufields[f_ctime] ?></td></tr>
<tr><td class="info">Name</td>
<td class="info"><?php echo $u->pfields[name] ?></td></tr>
<tr><td>Email (private)</td>
<td><?php print emailCloaking($u->ufields[email],0) ?></td></tr>
<tr><td>Email (public)</td>
<td>
<?php
$email_addresses = $u->get_public_email_addresses();
$count = count($email_addresses);
$index = 0;
while ($index < $count) {
   print emailCloaking($email_addresses[$index],0) . "<br>\n";
   ++ $index;
}
?>
</td></tr>
<tr><td>Homepage</td>
<?php 
if ($u->pfields[homepage] != "") {
   if (!preg_match("/^http:\/\//i", $u->pfields[homepage]) && !preg_match("/^https:\/\//i", $u->pfields[homepage])) {
      print "<td><a href=\"http://" . $u->pfields[homepage] .
	"\" target=\"_blank\">http://" . $u->pfields[homepage] . "</a></td></tr>\n";
   } else {
      print "<td><a href=\"" . $u->pfields[homepage] . "\" target=\"_blank\">" . $u->pfields[homepage] . "</a></td></tr>\n";
   } 
} 
?>
<tr><td>Country</td>
<td><?php echo $u->pfields[country] ?></td></tr>
<tr><td>State</td>
<td><?php echo $u->pfields[state] ?></td></tr>
<tr><td>City</td>
<td><?php echo $u->pfields[city] ?></td></tr>
</table>
<p>
You live in 
<?php
    $placeid = mysql_escape_string($u->pcfields[placeid]);
    $placeq = mysql_query("select * from places
         where name = '$placeid'");
    if ($placeq) {
       $place = mysql_fetch_array($placeq);
       if ($place) {
          # echo "Generating place bar for $place[longname]";
          place_bar($place);
       } else {
          echo "Did not find any entry for $placeid";
       }
    } else {
       echo "Error in fetching $placeid";
    }
?>
<p>
<a
href="/cgi-bin/runscript/show-user.cgi<?php maybecookie() ?>"
class="button"
>
Edit my person entry
</a>
<p>
<a href="emails.php" class="button">Edit my emails</a>
<p>
<a href="/cgi-bin/runscript/logout.cgi" class="button">Log Out</a>

<h2>My machines registered</h2>
<?php
   $query = mysql_query("SELECT machines.f_key, machines.name,
   unix_timestamp(automach.updated) as updatetime, automach.uptime,
   automach.uniqueid
          FROM machines LEFT JOIN automach ON machines.f_key = automach.f_key
		WHERE machines.owner = '" . currentuser() . "' ORDER BY f_key");
   if (!$query) {
         print mysql_error();
         die("Query failed");
   }
?>
<table class="info">
<tr><th>ID<th>Name<th>Last auto-update<th>Uptime</tr>
<?php
   while ($arr = mysql_fetch_array($query)) {
	# Try to suppress irritation from automach duplicates
	if ($prevkey <> $arr[f_key]) {
	    print "<tr><td>" . $arr[f_key];
            print "<td><a href=\"/cgi-bin/runscript/machine-show.cgi?machine=$arr[f_key]";
	    maybecookie("&amp;");
	    print "\">";
	    if ($arr[name]) {
	       print $arr[name];
            } else {
	       print "Nameless";
            }
	    print "</a>";
	    $prevkey = $arr[f_key];
        } else {
	   print "<tr><td> - also reported at - <td>";
       }
	print "<td>";
	if ($arr[updatetime]) {
	    print "<a href=\"show-automach.php?uniqueid="
	    . $arr[uniqueid];
	    maybecookie("&amp;");
	    print "\">";
	    print strftime("%Y-%m-%d %H:%M:%S", $arr[updatetime]);
	    print "</a>";
   	} else {
	    print "<a href=\"/scripts/\">No auto</a>";
        }
	if ($arr[uptime]) {
	    printf("<td>%.1f", $arr[uptime]);
        }
	print "\n";
   }
?>
</table>
<br>
<a href="/machine-form.php" class="button">Add a machine</a>
<p>
Grab the <a href="/scripts/" class="button">machine update script</a>
<p>
All information stored in the Linux Counter is subject to the Counter <a href="/organization/privacy.php">privacy policy</a>.


<?php pagebottom("yes") ?>
</body>
</html>


